FROM {{ namespace }}/{{ infra_image_prefix }}base:{{ tag }}
{% block labels %}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
{% endblock %}

{% block storm_base_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{{ macros.configure_user(name='storm', homedir='/opt/storm') }}

{% if base_package_type == 'rpm' %}
    {% set storm_packages = [
        'java-1.8.0-openjdk-headless',
    ] %}
{% elif base_package_type == 'deb' %}

    {% if base_distro == 'debian' %}
        {% set java_version = '11' %}
    {% elif base_distro == 'ubuntu' %}
        {% set java_version = '8' %}
    {% endif %}

    {% set storm_packages = [
        'openjdk-' + java_version + '-jre-headless',
    ] %}
{% endif %}

{{ macros.install_packages(storm_packages | customizable("packages")) }}

{% block storm_version %}
ENV storm_version=1.2.2
ENV storm_url=https://archive.apache.org/dist/storm/apache-storm-${storm_version}/apache-storm-${storm_version}.tar.gz
ENV storm_pkg_sha512sum=0a1120b8df7b22edc75f0a412d625841f72f3fb8e9ff5d413d510908d68ea1f0c17d68c1a7f1eda427b40902452e9efcae902c36499b558592e41cc1079de2e0
{% endblock %}

{% block storm_install %}
RUN curl -o /tmp/storm.tgz ${storm_url} \
    && echo "${storm_pkg_sha512sum} /tmp/storm.tgz" | sha512sum -c \
    && tar --strip 1 -xvf /tmp/storm.tgz -C /opt/storm \
    && rm -f /tmp/storm.tgz

{% endblock %}

{% block storm_python_version %}
# NOTE(dszumski): Storm needs to be told where the Py3 interpreter lives
{% if distro_python_version.startswith('3') %}
ENV PYTHON={{ '/usr/bin/python' ~ distro_python_version }}
{% endif %}
{% endblock %}

COPY extend_start.sh /usr/local/bin/kolla_extend_start
RUN chmod 755 /usr/local/bin/kolla_extend_start

{% block storm_base_footer %}{% endblock %}
